package se.topshelf.golftracker.web.controller.player;

import se.topshelf.golftracker.core.domain.GolfId;

import java.beans.PropertyEditorSupport;

/**
 *
 */
public class GolfIdEditor extends PropertyEditorSupport{

    @Override
    public void setAsText(String s) throws IllegalArgumentException {
        if(s == null || s.length() == 0){
            super.setValue(null);
        } else{
            setValue(GolfId.createGolfId(s.substring(0, 6), s.substring(7, 10)));
        }
    }

    @Override
    public String getAsText() {
        GolfId golfId = (GolfId) getValue();
        if(golfId == null){
            return null;
        }
        return golfId.getAsString();
    }
}
